package com.health.db.dao.user.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.health.db.dao.ServiceInterface;
import com.health.db.dao.user.ITrainingBaseDao;
import com.health.db.mapper.TrainingBaseMapper;
import com.health.db.model.TrainingBase;
import com.health.db.model.TrainingBaseExample;
import com.health.redis.RedisConstants;

/**
 * 培训基础表
 * @author YC
 *
 */
@Component("trainingBaseDao")
public class TrainingBaseDaoImpl extends ServiceInterface implements
		ITrainingBaseDao {

	@Autowired
	TrainingBaseMapper trainingBaseMapper;
	
	@Override
	public int insert(TrainingBase record) {
		// TODO Auto-generated method stub
		int executNum = trainingBaseMapper.insert(record);
		return executNum;
	}

	@Override
	public List<TrainingBase> selectByExample(TrainingBaseExample example) {
		// TODO Auto-generated method stub
		
		getRedisOperatiorLogic();
	    String key =RedisConstants.TrainingBaseMapper+":id:"+example.getId().longValue();
	    
	    Object object=null;
	    List<TrainingBase>  list = null;
      
        if(redisOperatiorLogic.isJedisIsConnected())
        {    
            object = redisOperatiorLogic.readObject(key, getPublicRedisGroupNo("1"));
         }
         if(null!=object){
        	 if (!object.equals("")) {
        		 list = ( List<TrainingBase> ) object;
			}
         }else{
        	 list= trainingBaseMapper.selectByExample(example);
          if(redisOperatiorLogic.isJedisIsConnected())
            {
                redisOperatiorLogic.setEx(key, list,  getOrderRedisGroupNo("1"));
             }
         }
        return list;
		
	}

	
/*    @Override
    public UserLIST selectByUserId(Long userId) {
        // TODO Auto-generated method stub
        getRedisOperatiorLogic();
        String key =RedisConstants.UserLISTMapper+selectByUserId+userId;
        
        Object object=null;
        UserLIST userLIST = null;
    
        if(redisOperatiorLogic.isJedisIsConnected())
        {    
            //get data from redis
            object = redisOperatiorLogic.readObject(key, getPublicRedisGroupNo("1"));
         }
         if(null!=object){
        	if (!object.equals("")) {
        		  userLIST =  (UserLIST) object;
			}
         }else{
          UserLISTExt example=new UserLISTExt();
         
          example.setUserid(userId);
        
          userLIST=userLISTMapper.selectByUserId(userId);
          if(redisOperatiorLogic.isJedisIsConnected())
            {redisOperatiorLogic.setEx(key, userLIST,  getOrderRedisGroupNo("1"));}
         }
    
        if (null==userLIST) {
            return null;
        }
        return userLIST;
    }*/

	
	@Override
	public TrainingBase selectByPrimaryKey(Long id) {
		// TODO Auto-generated method stub
		TrainingBase trainingBase = trainingBaseMapper.selectByPrimaryKey(id);
		
		return trainingBase;
	}

	@Override
	public int updateByPrimaryKeySelective(TrainingBase record) {
		// TODO Auto-generated method stub
		int executNum = trainingBaseMapper.updateByPrimaryKeySelective(record);
		return executNum;
	}

	@Override
	public int updateByPrimaryKey(TrainingBase record) {
		// TODO Auto-generated method stub
		int executNum =trainingBaseMapper.updateByPrimaryKey(record);
		return executNum;
	}

	public TrainingBaseMapper getTrainingBaseMapper() {
		return trainingBaseMapper;
	}

	public void setTrainingBaseMapper(TrainingBaseMapper trainingBaseMapper) {
		this.trainingBaseMapper = trainingBaseMapper;
	}

}
